package com.example.nophase.adapter;

import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.nophase.R;
import com.example.nophase.entity.ProjectDetailDTO;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

public class FinanceProjectListAdapter extends BaseAdapter {


    Context context;
    List<ProjectDetailDTO> projectListItemList;
    Boolean type;
    public FinanceProjectListAdapter(List<ProjectDetailDTO> projectListItemList, Context context,Boolean type) {
        this.type = type;
        this.projectListItemList = projectListItemList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return projectListItemList.size();
    }

    @Override
    public Object getItem(int position) {
        return projectListItemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.adult_form_project_lv_item, null);
        String project_plan = "";
        if (projectListItemList.get(position).getAppStep() != null) {
            if (!projectListItemList.get(position).getAppStep().equals("")) {
                project_plan = "(" + projectListItemList.get(position).getAppStep() + ")";
            }
        }

        //获取ListView中Image对象
        TextView adult_lv_item_title = view.findViewById(R.id.adult_lv_item_title);
        TextView adult_lv_money = view.findViewById(R.id.adult_lv_money);
        TextView adult_lv_instructions = view.findViewById(R.id.adult_lv_instructions);
        View layout = view.findViewById(R.id.update_money);
        if(type==false){
            layout.setVisibility(View.GONE);
        }

        TextView total_money = view.findViewById(R.id.total_money);
        TextView total_instructions = view.findViewById(R.id.total_instructions);
        TextView production_value = view.findViewById(R.id.production_value);

        adult_lv_item_title.setText(projectListItemList.get(position).getProName() + project_plan);
        adult_lv_money.setText(String.valueOf(projectListItemList.get(position).getAppMoney()));
        adult_lv_instructions.setText(String.valueOf(projectListItemList.get(position).getAuditMoney()));

        total_money.setText(getdivide(projectListItemList.get(position).getTyProMoneyVo().getProAppMoney()));
        total_instructions.setText(getdivide(projectListItemList.get(position).getTyProMoneyVo().getProAuditMoney()));
        if (projectListItemList.get(position).getRealMoney() != null) {
            production_value.setText(getdivide(projectListItemList.get(position).getRealMoney()));
        } else {
            production_value.setText("0");
        }


        return view;

    }

    private String getdivide(BigDecimal val1) {
        BigDecimal val2 = new BigDecimal(10000);
        BigDecimal decimal = val1.divide(val2);
        if (decimal.intValue() >= 1) {
            //方式一
            DecimalFormat df1 = new DecimalFormat("0.00");
            String str1 = df1.format(decimal.doubleValue());
            return str1 + "万";
        } else {
            DecimalFormat df2 = new DecimalFormat("0.0");
            String str2 = df2.format(val1.doubleValue());
            return str2 + "元";
        }
    }


}
